﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IMC.Prepare.Core.Infrastructure;
using IMC.Prepare.Core;
using IMC.Prepare.Core.Data;

namespace IMC.Prepare.Data
{
    public class EfStartUpTask : IStartupTask
    {
        public void Execute()
        {
            //if (!DataSettingsHelper.DatabaseIsInstalled())
            //    return;

            var settings = EngineContext.Current.Resolve<DataSettings>();
            if (settings != null && settings.IsValid())
            {
                var provider = EngineContext.Current.Resolve<IEfDataProvider>();
                if (provider == null)
                    throw new NopException("No EfDataProvider found");
                provider.SetDatabaseInitializer();
            }
        }

        public int Order
        {
            //ensure that this task is run first 
            get { return -1000; }
        }
    }
}
